{% macro search_box(settings, id=False, prefix=None, target=None,
                    params=None) %}
  <form data-instant-search="form" {% if id %}id="{{ id }}"{% endif %} action="{{ url('search') }}" method="get" {% if target %} target="{{ target }}"{% endif %} class="simple-search-form">
    {% if params %}
      {% for k, v in params.items() %}
        <input type="hidden" name="{{ k }}" value="{{ v }}" />
      {% endfor %}
    {% endif %}
    <input type="search" autocomplete="off" name="q" required="required" aria-required="true" placeholder="{{ _('Find help...')|truncate(12) }}" class="searchbox" id="search-q" />
    <button type="submit" title="{{ _('Search') }}" class="submit-button">{{ _('Search') }}</button>
  </form>
{% endmacro %}

{% macro aux_nav(user, hide_aaq_link=False) %}
  {% if not settings.READ_ONLY %}
    {% if not hide_aaq_link %}
      {% if request.LANGUAGE_CODE in AAQ_LANGUAGES %}
        {% set ask_url = url('questions.aaq_step1') %}
      {% else %}
        {% set ask_url = url('wiki.document', 'get-community-support') %}
      {% endif %}
    {% endif %}
    {% if user.is_authenticated() %}
      <li><a href="{{ ask_url }}" class="ask" data-event-category="navigation" data-event-action="main navigation" data-event-label="Get Community Support">{{ _('Get Community Support') }}</a></li>
      <li class="dropdown">
        <a href="#" data-event-category="navigation" data-event-action="main navigation" data-event-label="Contributor Tools">{{ _('Contributor Tools') }}</a>
        <ul class="double">
          {{ _for_contributor_links(user, settings.WIKI_DEFAULT_LANGUAGE) }}
        </ul>
      </li>
    {% else %}
      <li>
        <a href="{{ url('landings.get_involved') }}" class="volunteer-button" data-event-category="Volunteer Button" data-event-action="Volunteer for Mozilla Support">{{ _('Volunteer') }}</a>
      </li>
    {% endif %}
  {% endif %}
{% endmacro %}

{% macro content_editor(field) %}
  <div class="editor{% if field.errors %} invalid{% endif %}" data-media-search-url="{{ url('gallery.async') }}" data-media-gallery-url="{{ url('gallery.home') }}">
    <div class="editor-tools"></div>
    <div>{{ field|safe }}</div>
  </div>
  <div style="display: none;">
    <select id="_languages-select-box">
      {% for lang in settings.LANGUAGE_CHOICES %}
        <option value="{{ lang[0] }}" {% if lang[0] == request.LANGUAGE_CODE %}selected="selected"{% endif %}>{{ lang[1] }} ({{ lang[0] }})</option>
      {% endfor %}
    </select>
  </div>
{% endmacro %}

{% macro list_view_item(url, label, class=None, icon_url=None) %}
<li>
  <a href="{{ url }}"{% if class %} class="{{ class }}"{% endif %}>
    {% if icon_url %}
      <img class="icon" src="{{ icon_url }}" />
    {% endif %}
    {{ label }}
  </a>
</li>
{% endmacro %}

{% macro for_contributors_sidebar(user, default_language, li_only=False, active=None) -%}
  {% if user.is_authenticated() %}
    {% if not li_only %}
      <ul class="sidebar-nav sidebar-folding">
    {% endif %}
      <li id="for-contributors-sidebar"{% if active %} class="selected"{% endif %}>
        <a href="#">{{ _('For Contributors') }}</a>
        <ul class="sidebar-nav">
          {{ _for_contributor_links(user, default_language, active) }}
        </ul>
      </li>
    {% if not li_only %}
      </ul>
    {% endif %}
  {% endif %}
{%- endmacro %}

{% macro _for_contributor_links(user, default_language, active=None) -%}
  <li><a href="{{ url('landings.get_involved') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Quickstart Guide">{{ _('Quickstart Guide') }}</a></li>
  <li><a href="{{ url('wiki.document', 'contributor-news-resources') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="News &amp; Resources">{{ _('News &amp; Resources') }}</a></li>
  <li {{ active|class_selected('forums') }}><a href="{{ url('forums.forums') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Contributor Forums">{{ _('Contributor Forums') }}</a></li>
  <li {{ active|class_selected('article-discussions') }}><a href="{{ url('wiki.locale_discussions') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Article Discussions">{{ _('Article Discussions') }}</a></li>
  <li {{ active|class_selected('kbdashboard') }}><a href="{{ url('dashboards.localization') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Knowledge Base Dashboard">{{ _('Knowledge Base Dashboard') }}</a></li>
  <li><a href="{{ url('dashboards.aggregated_metrics') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Localization Metrics">{{ _('Localization Metrics') }}</a></li>
  <li><a href="{{ url('wiki.revisions') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Recent Revisions">{{ _('Recent Revisions') }}</a></li>
  <li><a href="{{ url('questions.home') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Support Forum Home">{{ _('Support Forum Home') }}</a></li>
  <li><a href="{{ url('questions.metrics') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Support Forum Metrics">{{ _('Support Forum Metrics') }}</a></li>
  {% if user.has_perm('flagit.can_moderate') %}
    <li><a href="{{ url('flagit.queue') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Moderate Forum Content">{{ _('Moderate Forum Content') }}</a></li>
  {% endif %}
  <li><a href="{{ url('gallery.home') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Media Gallery">{{ _('Media Gallery') }}</a></li>
  <li><a href="{{ url('search.advanced') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Advanced Search">{{ _('Advanced Search') }}</a></li>
  <li><a href="{{ url('kpi.dashboard') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="KPI Dashboard">{{ _('KPI Dashboard') }}</a></li>
  <li><a href="{{ url('community.home') }}" data-event-category="navigation" data-event-action="main navigation" data-event-label="Community Hub">{{ _('Community Hub') }}</a></li>
{%- endmacro %}

{# This is designed to be used like this:
  {% call announcement_bar('foo', 'info') %}
    This is the contents of the bar.
  {% endcall %}
#}
{% macro announcement_bar(id, level) -%}
  <div class="announce-bar {{ level }}" id="announce-{{ id }}">
    <div class="container_12">
      <div class="grid_12">
        <div class="close-button" data-close-id="announce-{{ id }}"></div>
        {{ caller() }}
      </div>
    </div>
  </div>
{% endmacro %}

{% macro favicon() %}
  <link rel="apple-touch-icon" sizes="180x180" href="{{ STATIC_URL }}sumo/img/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="{{ STATIC_URL }}sumo/img/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="{{ STATIC_URL }}sumo/img/favicon-16x16.png">
  <link rel="manifest" href="{{ STATIC_URL }}sumo/manifest.json">
  <link rel="shortcut icon" href="{{ STATIC_URL }}sumo/img/favicon.ico">
  <meta name="msapplication-config" content="{{ STATIC_URL }}sumo/browserconfig.xml">
  <meta name="theme-color" content="#ffffff">
{% endmacro %}
